# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=haskell-bytestring-show
pkgver=0.3.5.6
pkgrel=30
pkgdesc="Efficient conversion of values into readable byte strings."
url="https://hackage.haskell.org/package/bytestring-show"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/bytestring-show/${pkgver}/bytestring-show-${pkgver}.tar.gz"
        ghc9.patch)
sha512sums=('f59a041e30ec3b3eb9f971968606685ba5968dafc44d92ed50c9f7f124b891f48fc6612fdfc1a57f702e76e41f70c647e81c1919ab7fee194db9d97ddd73dd10'
            'cb78ab44527773ddc20565fff66bad6e7453a554cf39b1ab82d24e44699a22087867ad51c6cb64b6d6979323bc46779e6dfc92f8ba7aa6f31b4b44d0923d7b92')

prepare() {
    cd bytestring-show-$pkgver
    patch -p1 -i ../ghc9.patch
    gen-setup
}

build() {
    cd "$srcdir"/bytestring-show-${pkgver}

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd "${srcdir}/bytestring-show-${pkgver}"

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
